﻿Public Class IntBooleanColumnAttribute
    Inherits ColumnAttribute

    Public Property TrueValue As Integer = 1
    Public Property FalseValue As Integer = 0

    Public Overrides Sub SetValue(model As Object, val As Object)
        If IsDBNull(val) Then
            MyBase.SetValue(model, val)
        Else
            MyBase.SetValue(model, If(val = Me.TrueValue, True, False))
        End If
    End Sub

    Public Overrides Function GetValue(model As Object) As Object
        Dim t As Type = Me.GetPropertyType
        If t.Equals(GetType(Boolean)) = False Then Return MyBase.GetValue(model)

        Dim val As Boolean? = MyBase.GetValue(model)
        Return If(val Is Nothing, val, If(val, Me.TrueValue, Me.FalseValue))
    End Function

End Class
